package org.tpdata.api.specialdiseasedata.tianta;

import asserts.Asserts;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import common.*;
import exceptions.TestNGRetry;
import io.qameta.allure.Feature;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import org.testng.Assert;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import utils.Contants;
import utils.ExcelUtils;
import utils.GetFileMess;

import java.util.ArrayList;
import java.util.List;

import static common.TestStep.requestAndRespondBody;


@Feature("比较tianta筛选的指标和excel差异")
public class CompareIndex extends SetUpTearDown1 {

    public static final String system = "env.properties";
    Logger log = Logger.getLogger(CompareIndex.class);
    Data data = Login.login();

    static String filePath;

    static {
        try {
            filePath = new GetFileMess().getValue("COPD_PATH",system);
        } catch (ConfigurationException e) {
            e.printStackTrace();
        }
    }

    /*获取tianta指标*/

    @Parameters({"diseaseIds","uri"})
    @Test(description = "")
    public void GetTiantaIndex(String diseaseIds,String uri) {
//        final String requestUrl = "http://192.168.0.222:9000/api-sourcedata/dataIndex/dataIndexValue/getDataIndexValueTreeList.json";
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("diseaseIds","1");
//        json.put("diseaseIds", diseaseIds);
//        json.put("topCategoryIds", "15393,15535,15758,63327,63514,63777,63553,15782,15809,72980");
        json.put("topCategoryIds", "1");
        log.info(json.toString());

        Response response = RunCaseJson.runCase(json, "get", uri);
        String jsonStr = response.asString();
//        log.info("响应报文：" + jsonStr);

        JSONObject obj = JSON.parseObject(jsonStr);
        JSONArray contentArr = obj.getJSONArray("responseData");

        String url = RestAssured.baseURI + ":" + RestAssured.port + RestAssured.basePath + uri;
        requestAndRespondBody(url,json,jsonStr);
        //获取N叉树的 title值
        List<String> menulist = FilterIndex.getTitle(contentArr, "");

        log.info(menulist.toString());
       //获取excel的层级指标分类名
//        ArrayList<String>  resourcelist = new ExcelUtils(Contants.COPD_PATH,0).ReadExcel("指标值名称");
        ArrayList<String>  resourcelist = new ExcelUtils(filePath,0).ReadExcel("指标值名称");
//        log.info(resourcelist.toString());
        boolean flag=Asserts.VerityListDiff(menulist,resourcelist);
        Assert.assertEquals(flag, Contants.ASSERT_SUCCESS);
    }
}
